﻿namespace HuaWei.CommComp
{
    using DevExpress.XtraEditors;
    using HuaWei;
    using HuaWei.CommClass;
    using HuaWei.Common;
    using HuaWei.Windows.Forms;
    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Drawing;
    using System.IO;
    using System.Runtime.InteropServices;
    using System.Windows.Forms;

    public class FrmRegSys : Form
    {
        private string _str = string.Empty;
        private TextEdit edtRegNo;
        private IContainer icontainer = null;
        private LabelControl labelControl1;
        private LabelControl labelControl3;
        private SimpleButton simpleButton1;
        private SimpleButton simpleButton2;

        public FrmRegSys()
        {
            this.InitializeComponent();
        }

        public bool CheckLicense(string license, [Optional, DefaultParameterValue("")] string cpsn)
        {
            string str = "";
            string str2 = EncryptDecrypt.smethod2(license, "DdTtMmJl");
            if (cpsn.Equals(""))
            {
                str = SysUtils.GetComputerSerialNumber().Replace(":", "");
            }
            else
            {
                str = cpsn;
            }
            if (!str.Equals(str2))
            {
                MsgBox.ShowMsg("无效的注册文件，请与供应商联系获取有效的注册文件！");
                return false;
            }
            return true;
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.icontainer != null))
            {
                this.icontainer.Dispose();
            }
            base.Dispose(disposing);
        }

        private void euwcnUwWn(object sender, EventArgs e)
        {
            if (this.method1())
            {
                base.DialogResult = System.Windows.Forms.DialogResult.OK;
            }
        }

        private void FrmRegSys_Load(object sender, EventArgs e)
        {
            this.labelControl3.Visible = GParams._JGLX.Equals(JGLX.YZ);
            this.method();
        }

        private void InitializeComponent()
        {
            this.edtRegNo = new TextEdit();
            this.labelControl1 = new LabelControl();
            this.simpleButton1 = new SimpleButton();
            this.simpleButton2 = new SimpleButton();
            this.labelControl3 = new LabelControl();
            this.edtRegNo.Properties.BeginInit();
            base.SuspendLayout();
            this.edtRegNo.Location = new Point(12, 0x24);
            this.edtRegNo.Name = "edtRegNo";
            this.edtRegNo.Properties.ReadOnly = true;
            this.edtRegNo.Size = new Size(0x12a, 0x15);
            this.edtRegNo.TabIndex = 0;
            this.labelControl1.Location = new Point(12, 0x10);
            this.labelControl1.Name = "labelControl1";
            this.labelControl1.Size = new Size(0x24, 14);
            this.labelControl1.TabIndex = 1;
            this.labelControl1.Text = "注册号";
            this.simpleButton1.Location = new Point(0xd6, 0x4f);
            this.simpleButton1.Name = "simpleButton1";
            this.simpleButton1.Size = new Size(0x56, 0x17);
            this.simpleButton1.TabIndex = 4;
            this.simpleButton1.Text = "载入注册文件";
            this.simpleButton1.Click += new EventHandler(this.euwcnUwWn);
            this.simpleButton2.Location = new Point(0x132, 0x4f);
            this.simpleButton2.Name = "simpleButton2";
            this.simpleButton2.Size = new Size(0x39, 0x17);
            this.simpleButton2.TabIndex = 5;
            this.simpleButton2.Text = "取消";
            this.simpleButton2.Click += new EventHandler(this.simpleButton2_Click);
            this.labelControl3.Appearance.ForeColor = Color.Blue;
            this.labelControl3.Appearance.Options.UseForeColor = true;
            this.labelControl3.Location = new Point(12, 0x6c);
            this.labelControl3.Name = "labelControl3";
            this.labelControl3.Size = new Size(0x120, 14);
            this.labelControl3.TabIndex = 6;
            this.labelControl3.Text = "请把注册号发给供应商，获取注册文件进行系统注册。";
            base.AutoScaleDimensions = new SizeF(6f, 12f);
            base.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            base.ClientSize = new Size(0x178, 0x88);
            base.Controls.Add(this.labelControl3);
            base.Controls.Add(this.simpleButton2);
            base.Controls.Add(this.simpleButton1);
            base.Controls.Add(this.labelControl1);
            base.Controls.Add(this.edtRegNo);
            base.Name = "FrmRegSys";
            base.StartPosition = FormStartPosition.CenterScreen;
            this.Text = "系统注册";
            base.Load += new EventHandler(this.FrmRegSys_Load);
            this.edtRegNo.Properties.EndInit();
            base.ResumeLayout(false);
            base.PerformLayout();
        }

        private void method()
        {
            this.edtRegNo.Text = SysUtils.GetComputerSerialNumber().Replace(":", "");
        }

        private bool method1()
        {
            OpenFileDialog dialog = new OpenFileDialog();
            dialog.Filter = "注册文件|*.ltm";
            if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                string pToDecrypt = "";
                string fileName = dialog.FileName;
                StreamReader reader = new StreamReader(fileName);
                string str3 = "";
                ArrayList list = new ArrayList();
                while (str3 != null)
                {
                    str3 = reader.ReadLine();
                    if (!((str3 == null) || str3.Equals("")))
                    {
                        list.Add(str3);
                    }
                }
                reader.Close();
                for (int i = 0; i < list.Count; i++)
                {
                    pToDecrypt = pToDecrypt + list[i].ToString();
                }
                string license = EncryptDecrypt.Decrypt(pToDecrypt, EncryptDecrypt.EncryptionType.DES).Split(new char[] { '|' })[2];
                if (this.CheckLicense(license, this.edtRegNo.Text))
                {
                    string str5 = "License.ltm";
                    string destFileName = GParams.APP_PATH + str5;
                    File.Copy(fileName, destFileName, true);
                    return true;
                }
            }
            return false;
        }

        private void simpleButton2_Click(object sender, EventArgs e)
        {
            base.DialogResult = System.Windows.Forms.DialogResult.Cancel;
        }
    }
}

